//// ==UserScript==
// @name          Spacom compact skin
// @namespace     http://userstyles.org
// @description   v2.6 - 12:24 28/10/2009
// @author        Tiahin
// @include       http://spacom.ru/*
// @include       http://*.spacom.ru/*
// @exclude       http://wiki.spacom.ru/*
// ==/UserScript==
(function() {
var loc_act = location.search.substring(1, location.search.length);
var param_id_value = false;
var param_act_value = false;
var params = loc_act.split('&');
for (i = 0; i < params.length; i++) {
	param_name = params[i].substring(0,params[i].indexOf('='));
	if (param_name == 'id') param_id_value = params[i].substring(params[i].indexOf('=') + 1);
	if (param_name == 'act') param_act_value = params[i].substring(params[i].indexOf('=') + 1);
}
if (param_id_value) loc_id = param_id_value; else loc_id = '';
if (param_act_value) loc_act = param_act_value; else loc_act = '';
if (loc_act == '') loc_act = 'view';

var css = 
"html,body{background:#000 url(../image/background.jpg) no-repeat center top;} a{font:10px Verdana;color:#99BEC4} h3{font:bold 12px Verdana;color:#fff;padding-bottom:10px} td.c_center a,#general a{font:10px Verdana}" +
"#my_links{position:absolute;top:45px;left:5px} #my_buttons{position:absolute;top:45px;left:77px}" +
".menu li{list-style:none;float:left;width:94px} .clock{position:absolute;top:0px;left:77px} .menu_top{position:absolute;top:5px;left:270px} .menu_top.right{position:absolute;top:5px;left:580px}" +
"#left{width:435px;height:220px;border-right:none;margin-bottom:100px} .wrap{position:relative;min-height:600px;clear:both} #left .content li span{left:230px}" +
"#center{position:relative;float:right;width:563px;height:600px;border-left:1px solid #243948;border-right:1px solid #243948} #center .content{width:610px;height:600px;font:10px Verdana}" +
"#right{width:435px;height:280px;border-right:none} #right .content ul{padding-bottom:10px} .bonus{height:11px;padding-bottom:2px;} .bg1,.bg2{height:7px} .bonus .line{top:0px;font:11px Verdana;border:1px solid #043B58}" +
"#left .content,#right .content{font:10px Verdana;padding:20px 0px 0px 25px} #left .content li,#right .content li{padding-bottom:7px;width:310px}" +
".planet{width:550px;min-height:65px;margin-left:4px;} .planet .img{position:relative;width:65px;height:65px} .planet .img img{position:absolute;top:0;left:0;right:0;bottom:0;margin:auto;}" +
".politic1,.politic2,.politic3{margin-top:8px;margin-left:65px;border:solid 1px #043b58;opacity:0.4;}" +
".planet_p{width:450px} .planet ul{margin-top:10px} .planet li{position:relative;float:left;width:70px;white-space:nowrap} .queue{margin-left:300px;margin-top:-48px;font:italic 9px Verdana}" +
".podporka{background-image:none} #footer{overflow:none;padding: 5px 0px 5px 0px} .footer_header a{font-size:10px;color:#fff} .fleet_none{color:#00f}" +
"div.planet_robbery,div.planet_corrupt,div.planet_auditor{position:absolute;float:left;width:30px;height:30px;border:solid 1px #666}" +
"div.planet_robbery div,div.planet_corrupt div{background-color:rgba(31,31,31,0.5);font:bold 8px Verdana;margin-top:20px;height:12px} div.planet_auditor div{font:bold 10px Verdana;margin-top:18px}" +
"div.planet_robbery{z-index:46} div.planet_corrupt{z-index:47} div.planet_robbery div{color:#aaf;float:right} div.planet_corrupt div{color:#f00} div.planet_auditor div{color:#0f0;float:right}" +
"div.planet_auditor{z-index:48}" +
".footer_left,.footer_center,.footer_right{float:left;width:120px;display:block} .footer_header{font-size:10px;display:inline} #myFleets,#myPlanets,div.podporka,.footer_left p,.footer_center p,.footer_right p{display:none}" +
".reddd{color:#f00} .bolded{font-weight:bold} .bordered{border-top:solid 1px #666} .texted{font:10px Verdana} #geo td a.small,.planet_name a{font:12px Verdana} #geo td.right a.small,a.c_link,a.m_link{font:10px Verdana}" +
".planet_name a,#general a,a.small,a.c_link{color:aqua} .planet_name a:link,#general a:link,a.small:link,a.c_link:link,a.m_link:link{color:aqua} table.unit a img{width:35px;height:35px} table.unit a font{white-space:nowrap}" +
".planet_name a:visited,#general a:visited,a.small:visited,a.c_link:visited,a.m_link:visited{color:aqua} #general a:hover,a.small:hover,a.m_link:hover,a.c_link:hover,a.m_link:hover{font:10px Verdana;color:white;text-decoration:underline}" +
"div#general,div#mining{display:block;position:relative} div#general{padding:5px;float:left} div#mining{float:right} .clearing {clear:both;font-size:1px;height:0} div.aBuild,div.qBuild,div.canBuild{width:50px;height:50px;}" +
"div#mining,div#bonuses,div#control{padding:5px} #planet_controls ul,#building_controls ul,#bonuses a,#mining a,#control a,#general sup,#bonuses sup,#mining sup,#control sup{display:none}" +
"#building_controls div.menu_item:hover{color:#fff;background:#0078a3 url(images/ui-bg_glass_40_0078a3_1x400.png) 50% 50% repeat-x;}" +
"input,select{color:#333;background-color:#f0f0f0} input[type='button'],input[type='submit']{color:aqua;background-color:#223344;border-color:#04283f;padding:2px}" +
"#myPlanetName{font:bold 12px Verdana;padding:4px} #myPlanetName a{margin:0 15px} ";

param_name = 'div.podporka{display:inline}';
params = '<img src="image/map/fleets/own.png" alt="+"> Гарнизон (0)';

var js_body = 
"load_data('./?act=ajax_own_fleets&name=1','myFleets');myIsSetOwnData=false; ";

var js_code = 
"var e=document.getElementById('geo');var e_a=e.innerHTML;var e_span=e_a.match(/\\d+\\.\\d+/i);if(e_span!='"+loc_id+"')myIsSetOwnData=false;" +
"if(!myIsSetOwnData){" +
"var X=$('tr:eq(0)>td:eq(1)',$('#tablemap')).text();" +
"var Y=$('tr:eq(1)>td:eq(0)',$('#tablemap')).text();" +
"var url='./?act=ajax_stats_view&focus='+X+'.'+Y;" +
"var req=new Subsys_JsHttpRequest_Js();req.onreadystatechange = function() {" +
"if(req.readyState==4){X=req.responseJS;Y=X.split(':');var params;" +
"	for(var i=0;i< Y.length;i++){params=Y[i].split(',');X ='';" +
"		node=document.getElementById('map_'+ params[0]+'.'+params[1]);if(node){" +
"			if(params[2]>0){X =document.createElement('div');X.setAttribute('class','planet_robbery');X.innerHTML='<div>'+params[2]+'</div>';node.insertBefore(X,node.childNodes[0]);};" +
"			if(params[3]>0){X =document.createElement('div');X.setAttribute('class','planet_corrupt');X.innerHTML='<div>'+params[3]+'</div>';node.insertBefore(X,node.childNodes[0]);};" +
"};};};};req.open('GET',url,true);req.send({ }); " +
"var w=document.getElementById('myFleets'); e_span=w.getElementsByTagName('span'); e_a=w.getElementsByTagName('a'); " +
"i=0;while(i<e_span.length){e=document.getElementById('map_'+e_a[i].innerHTML);if(e){ " +
"	w=e_span[i].getElementsByTagName('img');if(w[0].alt=='!'){node=document.createElement('div');node.setAttribute('class','planet_auditor');node.innerHTML='<div>+</div>';e.insertBefore(node,e.childNodes[0]);}; " +
"};i++;};myIsSetOwnData=true;}else alert('Данные на карте!');";

var js =
"var myAllRobbery=0;var myAllCorrupt=0;var myAllRobLev=0;var myAllCorLev=0;" +
"var url='./?act=ajax_stats_view';var params=0;var req=new Subsys_JsHttpRequest_Js();req.onreadystatechange=function(){" +
"if(req.readyState==4){var w=req.responseJS;w=w.split(':');" +
"	for(var i=0;i<w.length;i++){params=w[i].split(',');" +
"		if(params[2]>0){myAllRobbery++;myAllRobLev+=parseInt(params[2]);};" +
"		if(params[3]>0){myAllCorrupt++;myAllCorLev+=parseInt(params[3]);};" +
"	}; if(myAllRobbery!=0){w='<li>Уровень грабежа <span>'+myAllRobLev+' из '+myAllRobbery + '00</span></li>';$('ul',$('#left')).append(w);};" +
"	if(myAllCorrupt!=0){w='<li>Уровень коррупции <span>'+myAllCorLev+' из '+myAllCorrupt + '00</span></li>';$('ul',$('#left')).append(w);};" +
"};};req.open('GET',url,true);req.send({ });" +
"$('div.politic1',$('div.planet'),$('#scrolled')).attr('title','Заселение');" +
"$('div.politic2',$('div.planet'),$('#scrolled')).attr('title','Ресурсы');" +
"$('div.politic3',$('div.planet'),$('#scrolled')).attr('title','Производство');";

var e = document.getElementById('cap');
var node = document.createElement('div');
node.setAttribute('id', 'my_links');
node.innerHTML = '<span onClick="document.location=\'?act=forum&CODE=event\'" title="Служебные сообщения" class="menu_item">СС</span>&nbsp;&nbsp;&nbsp;&nbsp;<span onClick="document.location=\'?act=forum&CODE=private\'" title="Личные сообщения" class="menu_item">ЛС</span>';
e.appendChild(node);
node = document.createElement('div');
node.setAttribute('id', 'my_buttons');
e.appendChild(node);

function xpath(expr, context) {
    if (!context) context = document;
	return document.evaluate(expr, context, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
}

function save_fleets(currentCoords) {
    ownFleetId = 'here_fleet_own(';
    here_own = document.getElementById('here_own');
    for (i = 0; i < here_own.childNodes.length; i++) {
        elem = here_own.childNodes[i];
        str = String(elem.onclick);
        if (str.indexOf(ownFleetId) !== -1) {
            fleetName = elem.childNodes[1].nodeValue;
            fleetId = str.substring(str.indexOf(ownFleetId)+ownFleetId.length, str.indexOf(')',str.indexOf(ownFleetId)));
            if(fleetName.indexOf('Гарнизон') == -1) {
                debug('foundFLeet:'+fleetId+': '+fleetName+' on '+currentCoords);
                window.localStorage.setItem('spacom_fleet_'+fleetId, currentCoords+'|'+fleetName);
            } else {
                debug('Найден гарнизон');
            }
        }
    };
}

function load_data(url, target) {
  var req = new Subsys_JsHttpRequest_Js();
  req.onreadystatechange = function() {
    if (req.readyState==4) {
        document.getElementById(target).innerHTML=req.responseJS;
        if (target == 'here_own') {
            save_fleets(url.substring(url.indexOf('id=')+3));
        }
    }
  }
  req.open('GET', url, true);
  req.send({ });
}

function move_fleet_new(fleet_id, xy){
    move_fleet_new_cancel();
    if (xy){
        fleetData = window.localStorage.getItem('spacom_fleet_'+fleet_id);
        fleetData = fleetData.split('|',2);
        fleetData[0] = xy;
        window.localStorage.setItem('spacom_fleet_'+fleet_id, fleetData.join('|'));
        load_data('./?act=ajax_move_fleet&id='+xy+'&fleet_id='+fleet_id, 'here_fleet_fly_'+fleet_id);
    }
} 

function delete_fleets() {
    storage = localStorage;
    if (typeof(unsafeWindow) !== 'undefined') {
        storage = unsafeWindow.localStorage;
    }
    for (i = 0; i < storage.length; i++) {
        key = storage.key(i);
        fleet = storage.getItem(key).split('|'); // адрес|название
        if (key.indexOf('spacom_fleet') != -1) {
            storage.removeItem(key);
        }
    }
}

function debug(str) {
    if (typeof(console) !== 'undefined' && (console.log)) {
        console.log(str);
    }
}

logos = xpath('//i[contains(@class,"icon")]');
for (i = 0; i < logos.snapshotLength; i++) {
	logos.snapshotItem(i).parentNode.removeChild(logos.snapshotItem(i));
}
xpath('//div[@id="cap"]').snapshotItem(0).style.height = "40px";
rasporka = xpath('//div[@id="rasporka"]').snapshotItem(0);
rasporka.style.height = "70px";
rasporka.style.background = "transparent url(../image/bg.png) repeat-x scroll 0 40px";
logo = xpath('//a[@class="logo"]').snapshotItem(0);
img = document.createElement('img');
img.setAttribute('src','../image/logo.png');
img.height = 30;
logo.appendChild(img);
logo.style.background = 'none';
logo.style.top = "0px";
clock = xpath('//div[@class="clock"]').snapshotItem(0);
clock.style.left = "150px";

switch (loc_act) {
	case "view":
		e = document.getElementById('scrolled');
		e = e.getElementsByTagName('i');
		i = 3;
		while (i < e.length){
			if (e[i].innerHTML > 10) e[i].innerHTML = '<b>' + e[i].innerHTML + '</b>';
			i += 5;
		}

		e = document.getElementById('center');
		node = e.getElementsByTagName('li');
		i = 4;
		while (i < node.length){
			node[i].removeAttribute('style');
			node[i].setAttribute('width', '140');
			i += 5;
		}

		e = document.getElementById('right');
		if (e) {
			node = e.getElementsByTagName('li');
			e = document.getElementById('left');
			e = e.getElementsByTagName('ul');
			e[0].appendChild(node[0]);
			e[0].appendChild(node[0]);
			e = document.getElementById('right');
			e = e.getElementsByTagName('div');
			node = e[0].getElementsByTagName('h3');
			e[0].removeChild(node[0]);
			node = e[0].getElementsByTagName('ul');
			e[0].removeChild(node[0]);

			e = document.getElementById('footer');
			node = document.createElement('div');
			node.setAttribute('id', 'myFleets');
			node.setAttribute('class', 'spoiler');
			e.appendChild(node);

			e = document.getElementById('footer');
			node = document.createElement('script');
			node.type = 'text/javascript';
			node.appendChild(document.createTextNode(js));
			e.appendChild(node);
		}
		css += param_name;
		
        // Добавляем ссылки на карту к изображениям планет
		planets = xpath('//div[@class="planet_name"]/a');
		for (i = 0; i < planets.snapshotLength; i++) {
			planet = planets.snapshotItem(i);
			href = planet.getAttribute('href');
			id = href.substr(href.indexOf('id='));
			container = xpath('ancestor::div[@class="planet"]/div[@class="img"]', planet).snapshotItem(0);
			container.innerHTML = '<a href="http://alpha.spacom.ru/?act=map&' + id + '">' + container.innerHTML + '</a>';
		}

        // Добавляем список флотов
        fleets = document.createElement('div'); 
        h2 = document.createElement('h3');
        h2.appendChild(document.createTextNode('Флоты'));
        fleets.appendChild(h2);
        storage = localStorage;
        if (typeof(unsafeWindow) !== 'undefined') {
            storage = unsafeWindow.localStorage;
        }
        var fleetCount = 0;
        for (i = 0; i < storage.length; i++) {
            key = storage.key(i);
            if (key.indexOf('spacom_fleet') != -1) {
                fleet = storage.getItem(key).split('|'); // адрес|название
                a = document.createElement('a');
                a.setAttribute('href', 'http://alpha.spacom.ru/?act=map&id='+fleet[0]);
                a.appendChild(document.createTextNode(fleet[1]));
                fleets.appendChild(a);
                fleets.appendChild(document.createElement('br'));
                fleetCount ++;
            }
        }	
        if (fleetCount == 0) {
            fleets.appendChild(document.createTextNode('Флотов не найдено'));
        } else {
            a = document.createElement('a');
            a.setAttribute('href','#');
            a.setAttribute('onclick', 'if(confirm("Точно?")){delete_fleets();}');
            a.innerText = 'Очистить';
            fleets.appendChild(a);
        }
        content = xpath('//div[@id="left"]/div[@class="content"]');
        content.snapshotItem(0).insertBefore(fleets, content.snapshotItem(0).firstChild);

        
		break;
	case "forum":
		break;
	case "planet":
		e = document.getElementById('planet_controls');
		if (e) {
			js = "document.onkeydown=myNavigateThrough; function myNavigateThrough(event){" +
				"if(!document.getElementById)return;if(window.event)event=window.event;var link=null;" +
				"switch(event.keyCode?event.keyCode:event.which?event.which:null){" +
				"case 0x25:link=document.getElementById('myButtonPrev');break;" +
				"case 0x27:link=document.getElementById('myButtonNext');break;" +
				"};if(link)document.location=link.href;};";

			node = document.createElement('div');
			node.setAttribute('class', 'clearing');
			e.insertBefore(node, e.childNodes[6]);

			if (loc_id != 0) {
				js_body = "var mySetOwnShips=false; function my_set_ships(){ if(!mySetOwnShips){load_data('./?act=ajax_construct&planet_id=" + loc_id + "', 'ships'); mySetOwnShips=true; }else{ toggle('ships');};};";
				e = document.getElementById('my_buttons');
				node = document.createElement('script');
				node.type = 'text/javascript';
				node.appendChild(document.createTextNode(js_body));
				e.appendChild(node);
			}

			e = document.getElementById('general');
			e = e.getElementsByTagName('a');
			node = document.createElement('div');
			node.setAttribute('id', 'myPlanetName');
			node.setAttribute('class', 'ui-widget-header ui-corner-all');
			node.innerHTML = e[0].innerHTML;
			e = document.getElementById('planet_controls');
			e.insertBefore(node, e.childNodes[0]);

			e = document.getElementById('general');
			e.className = '';
			e.setAttribute('style', 'width:222px;border-right:solid 1px #666');
			e = e.getElementsByTagName('table');
			e[0].setAttribute('width', '220');
			e[2].setAttribute('width', '220');

			e = document.getElementById('mining');
			e.className = '';
			e.setAttribute('style', 'width:170px');

			e = document.getElementById('bonuses');
			e.className = 'bordered';
			e = e.getElementsByTagName('td');
			node = e[7].innerHTML;
			i = node.match(/\d+\%/i);
			if (i != '0%') e[7].className += ' reddd bolded';

			e = document.getElementById('control');
			e.className = 'bordered';

			e = document.getElementById('goto');
			e.className = 'bordered';
			e = e.getElementsByTagName('option');
			i = 0;
			while (i < e.length){
				if (e[i].value == loc_id) {
					e[i].className = 'reddd bolded';
					e[i].innerHTML = '&gt; ' + e[i].innerHTML + ' &lt;';
					break;
				}
				i++;
			}

			w = document.getElementById('myPlanetName');
			if ((e[i-1])&&(i!=1)) {
				node = '<a id="myButtonPrev" href="?act=planet&id=' + e[i-1].value + '" title="' + e[i-1].innerHTML + '" class="c_link">&lt; пред</a>';
				w.innerHTML = node + w.innerHTML;
			}
			if (e[i+1]) {
				node = '<a id="myButtonNext" href="?act=planet&id=' + e[i+1].value + '" title="' + e[i+1].innerHTML + '" class="c_link">след &gt;</a>';
				w.innerHTML += node;
			}

			e = document.getElementById('footer');
			node = document.createElement('script');
			node.type = 'text/javascript';
			node.appendChild(document.createTextNode(js));
			e.appendChild(node);

			e = document.getElementById('building_controls');
			e = e.getElementsByTagName('div');
			i = 0;
			while (i < e.length){
				if (e[i].className == 'imgDiv') {
					node = e[i].getElementsByTagName('img');
					node[0].width = '40';
					node[0].height = '40';
				}
				i++;
			}

			e = document.getElementById('building_controls');
			node = document.createElement('div');
			node.setAttribute('class', 'menu_item ui-state-default');
			node.setAttribute('title', 'Список построенных зданий');
			node.setAttribute('onclick', "javascript:toggle('ready');");
			node.innerHTML = 'Построенные';
			e.insertBefore(node, e.childNodes[2]);
			node = document.createElement('div');
			node.setAttribute('class', 'menu_item ui-state-default');
			node.setAttribute('title', 'Очередь постройки');
			node.setAttribute('onclick', "javascript:toggle('now');");
			node.innerHTML = 'Очередь постройки';
			e.insertBefore(node, e.childNodes[5]);
			node = document.createElement('div');
			node.setAttribute('class', 'menu_item ui-state-default');
			node.setAttribute('title', 'Список доступных для строительства зданий');
			node.setAttribute('onclick', "javascript:toggle('can');");
			node.innerHTML = 'Строительство';
			e.insertBefore(node, e.childNodes[8]);
			node = document.createElement('div');
			node.setAttribute('class', 'menu_item ui-state-default');
			node.setAttribute('title', 'Список доступных для строительства кораблей');
			node.setAttribute('onclick', "javascript:my_set_ships();");
			node.innerHTML = 'Корабли';
			e.insertBefore(node, e.childNodes[11]);

			e = document.getElementById('ready');
			e.className = 'bordered';

			e = document.getElementById('now');
			e.className = 'bordered';

			e = document.getElementById('can');
			e.className = 'bordered';

			e = document.getElementById('ships');
			e.className = 'bordered';
			e.innerHTML = 'Нажмите для загрузки списка...';

		}
		break;
	case "map":

		js = "var myIsSetOwnData=false; function mySetOwnPlanets(){ " + js_code + "}; ";

		e = document.getElementById('footer');
		node = document.createElement('div');
		node.setAttribute('id', 'myFleets');
		node.setAttribute('class', 'spoiler');
		e.appendChild(node);

		e = document.getElementById('footer');
		node = document.createElement('div');
		node.setAttribute('id', 'myPlanets');
		node.setAttribute('class', 'spoiler');
		e.appendChild(node);

		e = document.getElementsByTagName('head');
		node = document.createElement('script');
		node.type = 'text/javascript';
		node.appendChild(document.createTextNode(js));
		e[0].appendChild(node);

		e = document.getElementById('my_buttons');
		node = document.createElement('script');
		node.type = 'text/javascript';
		node.appendChild(document.createTextNode(js_body));
		e.appendChild(node);

		e = document.getElementById('my_buttons');
		node = document.createElement('span');
		node.setAttribute('id', 'myPlanetsButton');
		node.setAttribute('class', 'menu_item');
		node.setAttribute('onclick', 'javascript:mySetOwnPlanets();');
		node.setAttribute('title', 'Показать флоты, коррупцию/грабеж');
		node.innerHTML = 'Мои планеты';
		e.appendChild(node);
		
        
		break;
	case "designs":
		e = document.getElementById('index2');
		if (e) {
			js = "function parseItD1(){setTimeout(function(){" +
				" len1=$('#new_designs').html().length;if(len1>30){" +
				"	$('td','form').removeAttr('colspan');" +
				"	$('td[width=120]','form').attr('rowspan','2');" +
				"	$('td[width=120]','form').attr('valign','top');" +
				"	$('td[width=120]','form').attr('height','130');" +
				"	$('td[width=120]','form').attr('width','110');" +
				" }else{parseItD1();}},250);} " +
				"function parseItD2(){setTimeout(function(){" +
				" len2=$('#designs').html().length;if(len2>30){" +
				"	$('img',$('table.left'),$('#designs')).width(55);" +
				"	$('img',$('table.left'),$('#designs')).height(55);" +
				"	$('tr',$('table.left'),$('#designs')).width(140);" +
				"	$('td[width=70]',$('table.left'),$('#designs')).width(60);" +
				"	$('td[width=70]',$('table.left'),$('#designs')).height(65);" +
				"	$('td[width=70]',$('table.left'),$('#designs')).removeAttr('width');" +
				"	len2=$('td',$('table.left'),$('#designs')).length;x=0;y=1;for(i=0;i<len2;i++){ " +
				"		$('tr:eq('+x+')',$('table.left'),$('#designs')).append($('tr:eq('+y+')',$('table.left'),$('#designs')).html());" +
				"		$('tr:eq('+y+')',$('table.left'),$('#designs')).remove();x++;y++; " +
				"	}; " +
				" }else{parseItD2();}},250);} " +
				"$(document).ready(function(){parseItD1();parseItD2();$('input.construct').change(function(){parseItD2();});});";

			e = document.getElementById('footer');
			node = document.createElement('script');
			node.type = 'text/javascript';
			node.appendChild(document.createTextNode(js));
			e.appendChild(node);
		}

		break;
	case "dip":
		break;
	case "science":
		break;
	case "options":
		break;
	case "active_players":
		css += param_name;
		break;
	case "states":
		css += param_name;
		break;
	case "players":
		css += param_name;
		break;
	case "quest":
		css += param_name;
		break;
	default:

		e = document.getElementById('center');
        if (e) {
            node = e.getElementsByTagName('li');
            i = 4;
            while (i < node.length){
                node[i].removeAttribute('style');
                node[i].setAttribute('width', '140');
                i += 5;
            }
    
            e = document.getElementById('right');
            if (e) {
                node = e.getElementsByTagName('li');
                e = document.getElementById('left');
                e = e.getElementsByTagName('ul');
                e[0].appendChild(node[0]);
                e[0].appendChild(node[0]);
                e = document.getElementById('right');
                e = e.getElementsByTagName('div');
                node = e[0].getElementsByTagName('h3');
                e[0].removeChild(node[0]);
                node = e[0].getElementsByTagName('ul');
                e[0].removeChild(node[0]);
    
                e = document.getElementById('footer');
                node = document.createElement('div');
                node.setAttribute('id', 'myFleets');
                node.setAttribute('class', 'spoiler');
                e.appendChild(node);
    
                e = document.getElementById('footer');
                node = document.createElement('script');
                node.type = 'text/javascript';
                node.appendChild(document.createTextNode(js));
                e.appendChild(node);
            }
        }
		css += param_name;
	}

if (typeof GM_addStyle != "undefined") {
	GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
	PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
	addStyle(css);
} else {
	e = document.getElementsByTagName("head");
	if (e.length > 0) {
		node = document.createElement("style");
		node.type = "text/css";
		node.appendChild(document.createTextNode(css));
		e[0].appendChild(node);
	}
}

function embedFunction(s) {
    document.body.appendChild(document.createElement('script')).innerHTML=s.toString().replace(/([\s\S]*?return;){2}([\s\S]*)}/,'$2');
}

function onWindowLoad () {
    debug('window loaded');
    if (document.getElementById('geo')) {
        currentCoords = document.getElementById('geo').firstChild.nodeValue;
        if (typeof(unsafeWindow) !== 'undefined') {
            unsafeWindow.save_fleets(currentCoords);
        } else {
            save_fleets(currentCoords);
        }
    }
}
embedFunction(load_data);
embedFunction(save_fleets);
embedFunction(debug);
embedFunction(move_fleet_new);
embedFunction(delete_fleets);

if (typeof(unsafeWindow) !== 'undefined') {
    unsafeWindow.onload = onWindowLoad;
} else {
    window.onload = onWindowLoad;
}

})();


